<?php
if (!defined('BASEPATH'))
	exit('No direct script access allowed');
//公司
class Company_model extends MY_Model
{
    private $table = 'company';
	public function __construct()
	{
		parent::__construct($this->table);	
	}
	//获取列表
	public function getList($where=[],$dbArray=[]){
	    $select='company.companyId,name,concat("'.IMAGEHOST.'",company.logo) as logo,concat("'.IMAGEHOST.'",company.poster) as poster,
                trade.typeName as tradeName,judge,consume,lat,lng, typeFlag';
	    $this->db->join('type as trade','trade.typeId=company.tradeId','left');

	    $this->db->where(['is_delete'=>0,'issue'=>1]);     //未删且发布
	    return $this->getWhere($where,$select,$dbArray);
	}
	//通过创建公司的用户ID来获取公司ID
	public function getCompanyIdByUserId($useId){
	    $company=$this->getWhereRow(['userId'=>$useId]);
	    if($company){
	        $companyId=$company['companyId'];
	        return $companyId;
	    }	    
	}

//	设为m2
    public function setM2($companyId)
    {
        $this->db->where('companyId', $companyId);
        $this->db->set('typeFlag', 'M2');
        $this->db->update('company');
        return $this->db->affected_rows();
    }

    public function getOne($companyId)
    {
        $this->db->where('companyId', $companyId);
         return $this->db->get('company')->row_array();
    }

    public function getMyCompany($userId)
    {
        $data['page'] = $this->input->post('page', TRUE);
        $data['limit'] = $this->input->post('limit', TRUE);
        $data['orderlist.userId'] = $userId;
        $data['company.is_delete'] = 0;
        $data['company.issue'] = 1;

        $this->_join('project','project.projectId=orderlist.listId','left');
        $this->_join('company','company.companyId=project.companyId','left');
        /*$this->_join('technician','technician.technicianId=orderlist.technicianId','left');
        $this->_join('company as c','technician.companyId=c.companyId','left');*/
        $this->_join('type as trade','trade.typeId=company.tradeId','left');
        $this->db->select('company.companyId,company.name,concat("'.IMAGEHOST.'",company.logo) as logo,concat("'.IMAGEHOST.'",company.poster) as poster,
                trade.typeName as tradeName,company.judge,company.consume,company.lat,company.lng, company.typeFlag');
        $this->_get_db($data);     //未删且发布
        $info = $this->db->get('orderlist')->result_array();
        return $info;
    }
}
?>